import React, { Component } from 'react'
import { Switch,Redirect,Route} from "react-router-dom"
interface IProps{
    route:any
}
export class routerView extends Component<IProps> {
    render() {
        let components=this.props.route.filter((item:any)=>item.component)
        let redirect=this.props.route.filter((item:any)=>item.redirect)
        return (
            <Switch>
                {
                    components.map((item:any,index:number)=>{
                        return <Route key={index} path={item.path} render={()=>{
                                if(item.children){
                                    console.log(1111)
                                    return <item.component route={item.children}></item.component>
                                }
                                return <item.component></item.component>
                        }}></Route>
                    })
                }
                {
                    redirect.map((item:any,index:number)=>{
                        return <Redirect key={index} from={item.path} to={item.redirect}></Redirect>
                    })
                }
            </Switch>
        )
    }
}

export default routerView
